package cn.fourhundredandeighteen.view.TeacherView.teacherInfo;


import cn.fourhundredandeighteen.UserInfo;
import cn.fourhundredandeighteen.controller.TeacherController;
import cn.fourhundredandeighteen.entity.Teacher;
import cn.fourhundredandeighteen.utill.NumberUtil;
import cn.fourhundredandeighteen.utill.Result;

import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class TeacherInfo {
    public TeacherController teacherController = new TeacherController();
    public Result<Teacher> teacherResult = teacherController.teacherInfo(UserInfo.Session);
    public Teacher teacherData = teacherResult.getData();//获取教師数组数据

    public Map<Integer, String[]> getteacherInfo(Long Session) {   //教師个人信息获取
        // TODO add your code here
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<Integer, String[]> integerStringHashMap = new HashMap<>();
        //获取字段
        String[] Lablename = {"工号:", "名字:", "年龄:", "密码:", "单位:", "电话:", "职称:", "更新时间:"};
        //获取数据

        String[] teacherdata = {
                String.valueOf(teacherData.getTeacherId()),
                String.valueOf(teacherData.getTeacherName()),
                String.valueOf(teacherData.getTeacherAge()),
                String.valueOf(teacherData.getTeacherPassword()),
                String.valueOf(teacherData.getTeacherSchool()),
                String.valueOf(teacherData.getTeacherPhone()),
                String.valueOf(teacherData.getTeacherTitle()),
                dateFormat.format(teacherData.getUpdateTime())
        };
        integerStringHashMap.put(1, Lablename);//数据键值对
        integerStringHashMap.put(2, teacherdata);
        return integerStringHashMap;
    }

    public String setTeacherInfo(ArrayList<JTextField> Data) {   //学生个人信息获取
        // TODO add your code here

        if (!NumberUtil.Password(String.valueOf(Data.get(3).getText()))) {
            return "请输入6位数字密码";
        }
        if (NumberUtil.Age(String.valueOf(Data.get(2).getText()))) {
            return "请输入正确年龄";
        }
//                if (NumberUtil.Major(String.valueOf(Data.get(3).getText()))){
//                        return "请输入正确的性别";
//                }
        //获取需要上传的数据并保存至数组
        Date date = new Date();
        teacherData.setTeacherAge(String.valueOf(Data.get(2).getText()));
        teacherData.setTeacherPassword(String.valueOf(Data.get(3).getText()));
        teacherData.setTeacherSchool(String.valueOf(Data.get(4).getText()));
        teacherData.setTeacherPhone(Integer.valueOf(String.valueOf(Data.get(5).getText())));
        teacherData.setTeacherTitle(String.valueOf(Data.get(6).getText()));
        teacherData.setUpdateTime(date);
        try {
            Result result = teacherController.upTeacher(teacherData);
            if (result.getMassage() == "SUCCESS") {
                return "修改成功";

            } else {
                return "修改失败";
            }
        } catch (NumberFormatException numberFormatException) {
            return "请输入正确的参数";
        }

    }

}